package com.imooc.producer.e_batch;

import com.utils.Const;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/4/10-2024
 * @Description: 这里用一句话描述这个类的作用
 */
public class BathProducer {
    public static void main(String[] args) throws Exception {
        //定义 producer
        DefaultMQProducer producer = new DefaultMQProducer("batch_producer");
        producer.setNamesrvAddr(Const.NAME_SERVER_SINGLE);

        //启动 producer
        producer.start();

        //定义批量消息
        List<Message> messageList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Message message = new Message(
                    "batch_topic",
                    "tags_batch_" + i,
                    "key_batch_" + i,
                    ("batch 消息" + i).getBytes());
            messageList.add(message);
        }

        //批量发送消息
        producer.send(messageList);

    }
}